import http from '../../utils/http'
import type {ApiResponse, PageResult} from '../../utils/ApiResponse'
import {Category, PageCategory} from "./types/categories.dto.ts";

// 获取所有商品分类
export const getAllCategories = (data: PageCategory): Promise<PageResult<Object>> => {
    return http.get(`/categories/info`, {
        params: {
            page: data.page,
            limit: data.limit,
            categoryName: data.categoryName,
        }
    })
}

// 添加分类信息
export const addCategory = (data: Category): Promise<ApiResponse<Object>> => {
    return http.post(`/categories/save`, data)
}

// 修改分类信息
export const saveCategoryInfo = (data: Category): Promise<ApiResponse<Object>> => {
    return http.put(`/categories/save`, data)
}

// 根据id删除分类信息
export const deleteCategoryById = (id: number): Promise<ApiResponse<Object>> => {
    return http.delete(`/categories/delete/${id}`)
}

// 根据id获取分类信息
export const getCategoryInfoById = (id: number): Promise<ApiResponse<Category>> => {
    return http.get(`/categories/info/${id}`)
}

